<template>
  <el-cascader
    :value="value"
    :options="options"
    separator="-"

    :props="{label: 'name', value: 'id'}"
    @change="handleChange"
  />
</template>

<script>
import { getDepartments } from '@/api/department'
import { transList2TreeData } from '@/utils'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      valuee: [],
      options: []

    }
  },
  created() {
    this.getDepartments()
  },
  methods: {
    // 获取部门的列表 转换为树形
    async getDepartments() {
      const res = await getDepartments()
      this.options = transList2TreeData(res, 0)
    },
    // 事件
    handleChange(value) {
    //   console.log(value)
      this.$emit('input', value[value.length - 1])
    }
  }
}
</script>

<style>

</style>
